/* Moderating effect of experience with CRP  */
clear
set more off 
eststo clear 



****** SS I and SS II ******

use "$dta/SS1and2.dta", clear

//particpated in any conservation activities?
// Federal CRP or any local or state programs
gen anycrp = crpindicator == 1 | noncrp == 1 


//covariates for SS I and SS II

#delimit ;
gl blcontrols i.gender i.itemnum totalacres age productionyears rowcropacres
  isagweek  i.state   ;
#delimit cr

rename personid person_id
rename slidervariation treat 

la def treat 0 "0%"  1 "100%" , replace 
la val treat treat 
la var treat "Default"

//interaction of high anchor with experience
gen treatanycrp = treat*anycrp 

** SS I ***

glm realbid i.treat##i.anycrp  $blcontrols if agvise == 1 , link(logit) family(binomial) vce(cluster person_id) nolog

*get marginal effect of treatment for participants with and without experience
margins , dydx(treat) over(anycrp) post
estimates store ESTagvise1
lincom _b[1.treat:0bn.anycrp] -  _b[1.treat:1.anycrp]
estadd scalar deltab = r(estimate)
estadd scalar deltase = r(se)

/*
------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |    .167819   .0660966     2.54   0.011      .038272     .297366
------------------------------------------------------------------------------
*/

*** SS II ***
drop anycrp
* experience = any CRP or state/federal program OR participated in SSI
gen anycrp = crpindicator == 1 | noncrp == 1 | inag1and2 == 1

glm realbid i.treat##i.anycrp  $blcontrols if agvise == 2 , link(logit) family(binomial) vce(cluster person_id) nolog

*get marginal effect of treatment for participants with and without experience
margins , dydx(treat) over(anycrp) post
estimates store ESTagvise2
lincom _b[1.treat:0bn.anycrp] -  _b[1.treat:1.anycrp]
estadd scalar deltab = r(estimate)
estadd scalar deltase = r(se)

/*
------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |   .0314846   .1166977     0.27   0.787    -.1972387    .2602078
------------------------------------------------------------------------------

*/


****** SS III *********

use "$dta/SS3.dta", clear

gen anycrp = iscrp == 2 | noncrp == 2

gen treatanycrp = default*anycrp

rename default treat

glm fracbid i.treat##i.anycrp   knowledge steward  age agyears owner i.gender  i.auction, link(logit) family(binomial) vce(cluster person_id)

margins , dydx(treat) over(anycrp) post
estimates store ESThogvise
lincom _b[1.treat:0bn.anycrp] -  _b[1.treat:1.anycrp]
estadd scalar deltab = r(estimate)
estadd scalar deltase = r(se)


/*
------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |   .0160952   .0357522     0.45   0.653    -.0539777    .0861682
------------------------------------------------------------------------------
*/

*******************************************************
// With AgVise and HogVise combined 
use "$dta/SSpooled.dta", clear 

gen anycrp = iscrp == 1 | noncrp == 1

replace anycrp = 1 if inag1and2 == 1 & agvise == 2

gen treatanycrp = default*anycrp

rename default treat
la def treat 0 "0%"  1 "100%" , replace 
la val treat treat 
la var treat "Default"


glm fracbid i.treat##i.anycrp  age agyears owner i.gender i.state  i.itemnum i.agvise , link(logit) family(binomial) vce(cluster person_id)

margins , dydx(treat) over(anycrp) post
estimates store ESTaghogvise
lincom _b[1.treat:0bn.anycrp] -  _b[1.treat:1.anycrp]
estadd scalar deltab = r(estimate)
estadd scalar deltase = r(se)


/*
------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |   .0221153   .0338852     0.65   0.514    -.0442984     .088529
------------------------------------------------------------------------------

*/

**** graph of estimates *****

#delimit ;
coefplot ESTagvise1, bylabel(StewardShares I) 
	||  ESTagvise2, bylabel(StewardShares II) 
	|| ESThogvise, bylabel(StewardShares III) 
	|| ESTaghogvise, bylabel(Pooled)
	||,
 coeflabels(0.anycrp* = "No " 
			1.anycrp* = "Yes", wrap(20) nobreak)
 groups(?.anycrp* = "{bf:Experience with cost-share auctions?}" )
 ciopts(recast(rcap) ) 
 msymbol(O) msize(medlarge) mcolor(black)
 legend(off) nooffset  
 xlabel(, nogrid labsize(vsmall) ) 
 scheme(s1mono) 
 plotregion(fcolor(white)) yscale(line) xscale(line) 
 xtitle("Marginal effect of starting bid value 100% (with 95% CI)") 
 byopts(xrescale iscale(*1.2) rows(1)) 
 subtitle(, size(small))
 mlabel format(%3.2f) mlabposition(12) mlabgap(*2)
 xline(0 , lpattern(dash) lcolor(gs12))
 name(gphv2, replace) 
;
#delimit cr


graph export "${outputs}/TreatmentEffect_by_CRPexperience.png", as(png) replace 


